<template>
  <div>
    <el-row>
      <el-col style="width:20%">
        <el-card class="box-card">
          <div><el-button style="width:100%;height:50px;" @click="handleChangeType(7)">中药用法</el-button></div>
          <div><el-button style="width:100%;height:50px;margin-top:10px;" @click="handleChangeType(10)">中药备注</el-button></div>
          <div><el-button style="width:100%;height:50px;margin-top:10px;" @click="handleChangeType(11)">药品分类</el-button></div>
          <div><el-button style="width:100%;height:50px;margin-top:10px;" @click="handleChangeType(16)">项目类型</el-button></div>
        </el-card>
      </el-col>

      <el-col style="width:79%;margin-left:1%">
        <el-card class="box-card">
          <el-form style="width: 775px">
          <el-form-item>
            <el-button type="primary" @click="toadd" style="width: 100px"
              >新增</el-button
            >
          </el-form-item>
        </el-form>
        <el-table :data="dataList" border style="width: 100%">
          <el-table-column fixed prop="did" label="序号"> </el-table-column>
          <el-table-column prop="dictionaryName" label="名称">
          </el-table-column>
          <el-table-column prop="type" label="来源" :formatter="statusFormatter"> </el-table-column>
          <el-table-column fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button @click="update(scope.row.ins_id)" type="primary" size="small">编辑</el-button>
              <el-button @click="del(scope.row.did)" type="primary" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Dictionary from "../../model/zyj/Dictionary";
const dictionary = Dictionary.getInstance();
export default {
  data() {
    return {
      dataList:[],
      params:{
        parentId: 7
      },
      form:{
        parentId: 7
      }
    };
  },
  created() {
        this.list();
  },

  methods: {
    list() {
            dictionary.list(this.params).then(({data}) => {
              this.dataList = data.data;
            });
    },
    statusFormatter(row) {
      if (row.type == '1') {
        return "系统";
      }
      if (row.type == '0') {
        return "自建";
      }
    },
    update(){
    },
     del(did) {
            this.$confirm('是否确定删除', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        dictionary.del(did).then(() => {
        this.list();
      });
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      }  ,
      
    toadd(){

    },
    handleChangeType(parentId){
        this.params.parentId = parentId
        this.form.parentId = parentId
        console.log(this.form.parentId)
        this.list()
    },
  }
  
}
</script>